package abd.pr1.Controllers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.sql.DataSource;

import abd.pr1.Interface.AdminSeriesPanel;
import abd.pr1.Interface.BuscarSeriesPanel;
import abd.pr1.Interface.EditarSerieWindow;
import abd.pr1.Interface.NuevaSerieWindow;
import abd.pr1.Interface.SerieWindow;
import abd.pr1.Mappers.SeriesMapper;
import abd.pr1.Models.Serie;
import abd.pr1.Models.Usuario;

public class AdminSeriesPanelController implements ActionListener{
	private AdminSeriesPanel adminSeriesPanel;
	private DataSource ds;

	
	public AdminSeriesPanelController( AdminSeriesPanel adminSeriesPanel, DataSource ds) {

		this.adminSeriesPanel = adminSeriesPanel;
		this.ds = ds;
		this.refreshSerie();
	}
	public void refreshSerie(){
		List<Serie> series=new SeriesMapper(ds).buscarNombreSerie(adminSeriesPanel.getBuscarTexto());
		this.adminSeriesPanel.setListaseries(series);
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand().equals("buscar_admin_serie")){
			List<Serie> series=new SeriesMapper(ds).buscarNombreSerie(adminSeriesPanel.getBuscarTexto());
			this.adminSeriesPanel.setListaseries(series);
		}else if (e.getActionCommand().equals("nueva_serie")){
			new NuevaSerieWindowController(this,new NuevaSerieWindow(), ds);
		}else if (e.getActionCommand().equals("info_admin_serie")){
			
			Serie serieSelected=this.adminSeriesPanel.getSelectedSerie();
			if(serieSelected!=null){
				new EditarSerieWindowController(new EditarSerieWindow(), ds,serieSelected);
			}
		}
		
		

	}

}
